﻿using UnityEngine;
using System.Collections.Generic;

public class SoundConfig : MonoBehaviour
{
    [System.Serializable]
    public class SoundClip
    {
        public string name;
        public int code;
        public AudioClip item;

        public SoundClip(string _name, AudioClip _item)
        {
            name = _name;
            item = _item;
            code = name.GetHashCode();
        }
    }

    public List<SoundClip> soundClips;
    public void SetClips(List<SoundClip> list)
    {
        soundClips = list;
    }

    public AudioClip GetAudioClip(string name)
    {
        //int code = name.GetHashCode();
        //for (int i = 0; i < soundClips.Count; i++)
        //{
        //    if (soundClips[i].code == code)
        //    {
        //        return soundClips[i].item;
        //    }
        //}

        for (int i = 0; i < soundClips.Count; i++)
        {
            if (soundClips[i].name == name)
            {
                return soundClips[i].item;
            }
        }
        return null;
    }

    public AudioClip GetAudioClip(int index)
    {
        if (soundClips.Count > index && index >= 0)
            return soundClips[index].item;
        return null;
    }
}